package cn.bxshey.webModule;

import cn.bxshey.commonModule.enums.ResultEnum;
import cn.bxshey.commonModule.result.Result;
import cn.bxshey.dtoModule.dynamic.SelectPageDTO;
import cn.bxshey.serviceModule.service.DynamicService;
import cn.bxshey.voModule.comments.SelectPageVO;
import cn.bxshey.voModule.dynamic.DetailVO;
import cn.bxshey.webModule.base.BaseController;
import com.alibaba.fastjson.JSON;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 动态
 *
 * @作者：不想说话而已
 * @Date：2024/3/11 0:35
 */
@RestController
@RequestMapping("/dynamic")
public class DynamicController extends BaseController {
    @Resource
    DynamicService dynamicService;

    /**
     * 查询动态详情内容
     *
     * @param id 主键id
     * @return 单个动态详情内容
     */
    @GetMapping("/{id}")
    public Result<DetailVO> selectById(@PathVariable("id") Long id) {
        return Result.success(dynamicService.selectById(id));
    }

    /**
     * 分页查询动态详情内容
     *
     * @param dto 查询参数
     * @return 多个动态详情内容
     */
    @GetMapping("/page")
    public Result<List<DetailVO>> selectPage(@ModelAttribute SelectPageDTO dto) {
        System.err.println(dto);
        return Result.success(dynamicService.selectPageDTO(dto));
    }

    /**
     * 检查文章是否点赞
     * @param id 动态文章id
     * @return true已点赞，false未点赞
     */
    @GetMapping("/isSupport/{id}")
    public Result<Boolean> isSupport(@PathVariable("id") Long id) {
//        String uid = String.valueOf(getUserLoginInfo().get("uid"));
        return Result.success(dynamicService.isSupport(id,1L));
    }

    /**
     * 文章点赞
     *
     * @param id 文章id
     * @return 无返回详细内容
     */
    @PutMapping("/support")
    public Result<List<SelectPageVO>> updateSupport(@Param("id") Long id) {
//        String uid = String.valueOf(getUserLoginInfo().get("uid"));
        Boolean aBoolean = dynamicService.updateSupport(id, 1L);
        return Result.success(ResultEnum.SUCCESS.code, aBoolean ? "已点赞" : "取消点赞", null);
    }


}
